﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PPIDesktopClient.Entities;
using System.Data;
using PPIProxy;
using PPIDesktopClient.General;
using VMind.Global;

namespace PPIDesktopClient.Logic
{
    public static class LLookup
    {
        public static List<ELookup> SelectAllbyType(string type)
        {
            List<ELookup> _ListLooks = new List<ELookup>();
            ELookup _look;
            try
            {
                ConfigReader _Reader = ConfigReader.GetInstance();
                DataTable _Datatable = WLookUp.SelectAllbyType(type,_Reader.GetConnectionString()).Tables[0];
                foreach (DataRow dr in _Datatable.Rows)
                {
                    _look = new ELookup();
                    _look.LookupId = ConvertHelper.ToInt32(dr["LookupId"]);
                    _look.LookupText = ConvertHelper.Tostring(dr["LookupText"]);
                    _look.LookupValue = ConvertHelper.ToInt32(dr["LookupValue"]);
                    _look.LookupType = ConvertHelper.Tostring(dr["LookupTypeFk"]);
                    _ListLooks.Add(_look);
                }
                return _ListLooks;
            }
            catch (Exception ex)
            {
                ErrorManager.Log("ex", "LLookup.SelectAllbyType() " + ex.Source, ex.Message, ex.StackTrace);
                return _ListLooks;
            }
            
            



            

        }

        public static EBaseLookup SelectbyType(EBaseLookup lookup)
        {
            EBaseLookup _look = new EBaseLookup();
            try
            {
                ConfigReader _Reader = ConfigReader.GetInstance();
                DataTable _Datatable = WLookUp.SelectAllbyType(lookup.Type,_Reader.GetConnectionString()).Tables[0];
                if (_Datatable.Rows.Count > 0)
                {
                    DataRow dr = _Datatable.Rows[0];
                    _look.Name = dr["LookupText"].ToString();
                }
                return _look;
            }
            catch (Exception ex)
            {
                ErrorManager.Log("ex", "LLookup.SelectAllbyType() " + ex.Source, ex.Message, ex.StackTrace);
                return new EBaseLookup();
            }







        }
    }
}
